﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GenericUndoRedo;

namespace FontTool
{
    abstract class nFontMemento : IMemento<nFontPool>
    {
        #region IMemento<nFontPool> Members

        public abstract IMemento<nFontPool> Restore(nFontPool target);

        #endregion
    }

    class InsertnFontMemento : nFontMemento
    {
        private int index;
        public InsertnFontMemento(int index)
        {
            this.index = index;
        }

        public override IMemento<nFontPool> Restore(nFontPool target)
        {
            nFont removed = target[index];
            IMemento<nFontPool> inverse = new RemovenFontMemento(index, removed);
            target.RemoveAt(index);
            return inverse;
        }
    }

    class RemovenFontMemento : nFontMemento
    {
        nFont removed;
        int index;
        public RemovenFontMemento(int index, nFont removed)
        {
            this.index = index;
            this.removed = removed;
        }

        public override IMemento<nFontPool> Restore(nFontPool target)
        {
            IMemento<nFontPool> inverse = new InsertnFontMemento(index);
            target.Insert(index, removed);
            return inverse;
        }
    }

    class AddnFontMemento : nFontMemento
    {
        public AddnFontMemento()
        {
        }

        public override IMemento<nFontPool> Restore(nFontPool target)
        {
            int index = target.Count - 1;
            IMemento<nFontPool> inverse = new RemovenFontMemento(index, target[index]);
            target.RemoveAt(target.Count - 1);
            return inverse;
        }
    }
}
